<template>
  <div class="accountDetails auntProfit">
    <div class="accountInput accountDetailsI displayFlex">
      <section class="myDatePickerBox displayFlex">
        <div class="datePickerItem">
          <DatePicker type="date" v-model="accountSubmit.startStr" placeholder="请选择..." style="width: 200px;" @on-change="handleChange"></DatePicker>
        </div>
        <div class="datePickerItem">
          <DatePicker type="date" v-model="accountSubmit.endStr" placement="bottom-end" placeholder="请选择..." style="width: 200px;" @on-change="handleChangeEnd"></DatePicker>
        </div>
      </section>
      <section class="accountBtnCx" @click="initData">
        <p>查询</p>
      </section>
    </div>
    <nav class="accountWhole">
      <li v-for="(count,countIndex) in accountNav"
          :class="{'on': count.type === accountId && (parseInt(subTypeId === 0) || subTypeId === count.subType)}"
          @click="accountEvent(count.type, count.subType)"><p><span class="round"></span>{{count.name}}</p></li>
    </nav>
    <nav class="accountBetNav displayFlex">
      <li v-for="t in typeList"><p>{{t}}</p></li>
    </nav>
    <div class="accountViewList">
      <ul>
        <li v-for="finan in financialData" class="displayFlex">
          <section><p>{{finan.typeText}}</p></section>
          <section><p>{{_Util.formatDateTime(finan.createTime)}}</p></section>
          <section><p>{{checkIncomeExpenses(finan.type,finan.subType)=='in'?finan.cash:'0'}}<span v-if="finan.type=='1'">(+{{finan.giftAmount}})</span></p></section>
          <section><p>{{checkIncomeExpenses(finan.type,finan.subType)=='out'?finan.cash:'0'}}</p></section>
          <section><p>{{finan.amount}}</p></section>
          <section><p>{{finan.note}}</p></section>
        </li>
      </ul>
    </div>
    <div class="pageDevice">
      <Page :total="totalPage" :pageSize='accountSubmit.pageSize' :current="accountSubmit.pageNum" :showTotal='true'
            @on-change="changeCurrentPage"></Page>
    </div>
  </div>
</template>

<script>
  import './accountDetails.scss';

  export default {
    data() {
      return {
        accountNav: [
          {type: 0, subType: 0, name: '全部'},
          {type: 3, subType: 0, name: '投注'},
          {type: 5, subType: 0, name: '彩票返水'},
          {type: 3, subType: 3, name: '撤单'},
          {type: 2, subType: 0, name: '提现记录'},
          {type: 1, subType: 0, name: '充值记录'},
          {type: 4, subType: 0, name: '中奖'},
          {type: 3, subType: 4, name: '打和返款'},
          {type: 6, subType: 0, name: '代理返点'},
        ],
        accountId: 0,
        subTypeId: 0,
        typeList: ['类型', '时间', '收入', '支出', '余额', '备注'],
        /*资金明细数据*/
        financialData: [],
        //提交数据
        accountSubmit: {
          type: '',
          subType: '',
          pageNum: 1,
          startStr: '',
          pageSize: 15,
          endStr: ''
        },
        totalPage: 0,//总条数
      }
    },
    activated() {
      this.init();
      if(this.$route.query.actionType){
        this.accountEvent(parseInt(this.$route.query.actionType),0);
      }else{
        this.initData();
      }
    },
    mounted() {
      this.spacing();
    },
    deactivated() {
      this.init();
    },
    methods: {
      init() {
        let that = this;
        that.accountId = 0;
        that.accountSubmit.type = '';
        that.accountSubmit.subType = '';
        that.accountSubmit.startStr = '';
        that.accountSubmit.endStr = '';
        that.accountSubmit.pageNum = 1;
        that.accountSubmit.pageSize = 15;
      },
      initData() {
        let that = this;
        that.accountSubmit.type = that.accountSubmit.type == '0' ? '' : that.accountSubmit.type;
        that._Util.post(that, that._Api.POST_GET_CASH_PAGE, that.accountSubmit, (data) => {
          that.financialData = data.result || [];
          that.totalPage = data.total || 0;
          that.accountSubmit.pageSize = data.pageSize || 15;
        });
      },
      //收支判断
      checkIncomeExpenses(type, subType) {
        if ((type == 1 || type == 4 || type == 5 || type == 6) || (type == 2 && subType == 7) || (type == 3 && (subType == 3 || subType == 4))||(type==7)&&(subType==2)) {
          return 'in';
        }
        if ((type == 2 && subType != 7) || (type == 3 && (subType != 3 || subType != 4))||(type==7)&&(subType==1)) {
          return 'out';
        }
      },
      //当前页数改变
      changeCurrentPage(val) {
        this.accountSubmit.pageNum = val;
        this.initData();
      },
      spacing() {},
      accountEvent(type, subType) {
        let that = this;
        that.accountId = type;
        that.accountSubmit.type = type;
        that.subTypeId = subType;
        that.accountSubmit.pageNum = 1;
        that.accountSubmit.startStr = '';
        that.accountSubmit.endStr = '';
        that.accountSubmit.subType = parseInt(subType) === 0 ? '' : subType;
        that.initData();

      },
      handleChange(date) {
        this.accountSubmit.startStr = date;
      },
      handleChangeEnd(date) {
        this.accountSubmit.endStr = date;
      }
    },
    watch: {}
  }
</script>
